package com.traffic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.traffic.domain.PerContractFile;
import com.traffic.service.IPerContractFileService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 合同备案表Controller
 * 
 * @author 郭世纪
 * @date 2024-12-08
 */
@RestController
@RequestMapping("/file")
public class PerContractFileController extends BaseController
{
    @Autowired
    private IPerContractFileService perContractFileService;

    /**
     * 查询合同备案表列表
     */
    @RequiresPermissions("personnel:file:list")
    @GetMapping("/list")
    public TableDataInfo list(PerContractFile perContractFile)
    {
        startPage();
        List<PerContractFile> list = perContractFileService.selectPerContractFileList(perContractFile);
        return getDataTable(list);
    }

    /**
     * 导出合同备案表列表
     */
    @RequiresPermissions("personnel:file:export")
    @Log(title = "合同备案表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PerContractFile perContractFile)
    {
        List<PerContractFile> list = perContractFileService.selectPerContractFileList(perContractFile);
        ExcelUtil<PerContractFile> util = new ExcelUtil<PerContractFile>(PerContractFile.class);
        util.exportExcel(response, list, "合同备案表数据");
    }

    /**
     * 获取合同备案表详细信息
     */
    @RequiresPermissions("personnel:file:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(perContractFileService.selectPerContractFileById(id));
    }

    /**
     * 新增合同备案表
     */
    @RequiresPermissions("personnel:file:add")
    @Log(title = "合同备案表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PerContractFile perContractFile)
    {
        return toAjax(perContractFileService.insertPerContractFile(perContractFile));
    }

    /**
     * 修改合同备案表
     */
    @RequiresPermissions("personnel:file:edit")
    @Log(title = "合同备案表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PerContractFile perContractFile)
    {
        return toAjax(perContractFileService.updatePerContractFile(perContractFile));
    }

    /**
     * 删除合同备案表
     */
    @RequiresPermissions("personnel:file:remove")
    @Log(title = "合同备案表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(perContractFileService.deletePerContractFileByIds(ids));
    }
}
